<?php 
    session_start();
    $resLink = mysqli_connect("localhost","root","","user");
    if(!$resLink){
        $err = mysqli_error($resLink);
        if($err){
            printf("连接错误:%s.\n 错误码: %s\n",$err, mysqli_errno($resLink));
            exit;
        }
    }
    mysqli_query($resLink, "set character set utf8 ");
    mysqli_query($resLink, "set character_set_results =utf8 ");
    $username = $_POST["username"];
    $password = $_POST["password"];
    $authcode = $_POST["authcode"];
    if($authcode != $_SESSION["authcode"]){
        echo '3';
        exit;
    }
    if($username && $password){
        $qString = "select * from userinfo where username = '$username' and password = '$password'";
        $Query_ID = mysqli_query($resLink,$qString);
        $rows = mysqli_num_rows($Query_ID);
        if($rows){
            $_SESSION["username"] = $username;
            echo "1";
        }
        else{
            echo "2";
        }
    }
    else{
        echo "0";
    }
    
?>